//simplify2 is new edition of simplify,
//it allows you to operate with multiple outlines: each node is elimineated or leaved in all the outline,
//simplify is leaved intact because it's well tested and commented

//simplification is elimination of contour's nodes
#pragma once

#include "outline.h"

namespace outline {

typedef unsigned int uint;

///template argument T in most functions is point<T> or vector< point<T> >,
///argument leaved_sample_numbers in half of functions
///receives indeces of original samples that was not eliminated

template <typename T>
void copy_samples(std::vector<T> const & src, 
	std::vector<uint> const & leaved_sample_numbers, std::vector<T> & dst)
{
	dst.clear();
	dst.reserve(leaved_sample_numbers.size());
	for (uint i = 0; i < leaved_sample_numbers.size(); ++i)
		dst.push_back(src[leaved_sample_numbers[i]]);
}

///simplification of single outline
///\param it is acceptable for src and dst to coincide
///\return measure of discrepancy between nodes of source outline and simplified outline
template <typename T>
double simplify_min_step_len(int min_step_len,
	std::vector<T> const & src, std::vector<uint> & leaved_sample_numbers);
template <typename T>
double simplify_min_step_len(int min_step_len,
	std::vector<T> const & src, std::vector<T> & dst);

///exactly K nodes in contour is leaved
template <typename T>
double simplify_to_K_nodes(int K,
	std::vector<T> const & src, std::vector<uint> & leaved_sample_numbers);
template <typename T>
double simplify_to_K_nodes(int K,
	std::vector<T> const & src, std::vector<T> & dst);

///(minimal number of nodes is leaved providing error less than given argument)
template <typename T>
double simplify_max_discrepancy(double max_discrepancy,
	std::vector<T> const & src, std::vector<uint> & leaved_sample_numbers);
template <typename T>
double simplify_max_discrepancy(double max_discrepancy,
	std::vector<T> const & src, std::vector<T> & dst);

} //namespace outline
